home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 21.8 KB | 993 lines | [TEXT/MPS ] |
- /*
- File: TestTimeScheduler.cp
-
- Contains: Tester for the TTimeScheduler class
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __TESTTIMESCHEDULER__
- #include "TestTimeScheduler.h"
- #endif
-
- #ifndef __LIBRARYMANAGERUTILITIES__
- #include <LibraryManagerUtilities.h>
- #endif
-
- const size_t kNumOps = 5;
-
- #define kCloseness 1
-
- size_t StringToNum(char* str);
- size_t RandomNumber(size_t lo, size_t hi);
-
- /**********************************************************************
- ** TTimeOperation methods
- ***********************************************************************/
-
- TTimeOperation::TTimeOperation(TTimeScheduler* theSched, int which)
- {
- fSched = theSched;
- fTest = 0;
- fWatch = NULL;
- fWhich = which;
- fFired = false;
- }
-
- TTimeOperation::~TTimeOperation()
- {
- if (fTest != 9)
- DebugBreak("In TTimeOperation destructor when we shouldn't be!");
- delete fWatch;
- fTest = 10;
- }
-
- void TTimeOperation::Process()
- {
- switch (fTest)
- {
- case 0:
- if (fFired)
- DebugBreak("Bummer - timer fired a second time");
- fFired = true;
- break;
-
- case 1:
- if (fFired)
- DebugBreak("Bummer - timer fired a second time");
- fFired = true;
- if (!fSched->Remove(this))
- DebugBreak("Bummer - remove didn't work");
- else
- {
- if (!fSched->DeleteInProcessOperation(this))
- DebugBreak("Scheduler won't process DeleteInProcessOperation call");
- else
- {
- if (!WasRemovedInProcess())
- DebugBreak("WasRemovedInProcess returned false");
- ClearRemovedInProcess();
- }
- }
- break;
-
- case 2:
- if (!fSched->Remove(this))
- DebugBreak("Bummer - remove didn't work");
- else
- {
- if (!fSched->RerunInProcessOperation(this))
- DebugBreak("Scheduler won't process RerunInProcessOperation call");
- else
- {
- if (!WasRemovedInProcess())
- DebugBreak("WasRemovedInProcess returned false");
- fTest = 3;
- }
- }
- break;
-
- case 3:
- fFired = true;
- if (!WasRemovedInProcess())
- DebugBreak("WasRemovedInProcess returned false");
- ClearRemovedInProcess();
- break;
-
- case 4:
- fFired = true;
- SetTime((kNumOps + 1)*500 - fWhich*500);
- fTest = 5;
- break;
-
- case 5:
- if (!fFired)
- DebugBreak("Bummer - haven't already fired");
- fTest = 20;
- break;
-
- case 6:
- fFired = true;
- if (!fSched->Remove(this))
- DebugBreak("Bummer - remove didn't work");
- SetTime((kNumOps + 1)*500 - fWhich*500);
- fTest = 7;
- fSched->Schedule(this);
- break;
-
- case 7:
- DebugBreak("Bummer - shouldn't get here");
- fTest = 21;
- break;
-
- case 8:
- fFired = true;
- SetDeleteWhenDone();
- fTest = 9;
- break;
-
- case 30:
- unsigned long temp = fWatch->ElapsedMilliseconds();
- fFired = true;
- fDifference = (int)(temp - fWhen);
- break;
-
- }
- }
-
- /**********************************************************************
- ** Class TTimeMatcher
- ***********************************************************************/
-
- class TTimeMatcher : public TMatchObject
- {
- public:
- TTimeMatcher(int toMatch);
- virtual ~_CDECL TTimeMatcher();
-
- virtual Boolean _CDECL IsEqual(const void*) const;
-
- int fMatch;
- };
-
- TTimeMatcher::TTimeMatcher(int toMatch)
- {
- fMatch = toMatch;
- }
-
- TTimeMatcher::~TTimeMatcher()
- {}
-
- Boolean TTimeMatcher::IsEqual(const void* obj) const
- {
- return ((const TTimeOperation*)obj)->fWhich == fMatch;
- }
-
- /**********************************************************************
- ** PUBLIC Constructor/Destructor
- ***********************************************************************/
-
- Constructor(TimeScheduler)
- Destructor(TimeScheduler)
-
- /**********************************************************************
- ** PUBLIC InitTest
- ***********************************************************************/
-
- void TTestTimeScheduler :: InitTest(BooleanParm, BooleanParm, int argc, char** argv)
- {
- size_t idx;
- TStandardPool* pool = GetPool();
-
- if (pool == NULL)
- {
- Printf("### ERROR: There is no global pool\n");
- return;
- }
-
- if ((fTest = new (pool) TTimeScheduler) == NULL)
- Printf("### ERROR: Couldn't create a new TTimeScheduler\n");
-
- fTest->SetAutoReschedule(true);
- fNumOperations = kNumOps;
- fResolution = 50;
- fIterations = 100;
- fStress = false;
- fMaxSchedule = 2500;
- fMinSchedule = 1;
- idx = 0;
- while (argc)
- {
- char* str;
-
- str = argv[idx];
- if (*str != '-')
- break;
- argc -= 1;
- idx += 1;
- switch (str[1])
- {
- case 'n':
- case 'N':
- fNumOperations = StringToNum(argv[idx++]);
- argc -= 1;
- break;
-
- case 'm':
- case 'M':
- if (argc >= 2)
- {
- fMinSchedule = StringToNum(argv[idx++]);
- fMaxSchedule = StringToNum(argv[idx++]);
- argc -= 2;
- if (fMinSchedule == 0 || fMaxSchedule == 0 ||
- fMinSchedule > fMaxSchedule)
- {
- fMaxSchedule = 2500;
- fMinSchedule = 1;
- Printf("WARNING: -m option expects min and max time following\n", str);
- }
- }
- else
- {
- Printf("WARNING: Option at and after '-m' not understood!\n", str);
- }
- break;
-
- case 'r':
- case 'R':
- fResolution = StringToNum(argv[idx++]);
- argc -= 1;
- break;
-
- case 'i':
- case 'I':
- fIterations = StringToNum(argv[idx++]);
- argc -= 1;
- break;
-
- case 's':
- case 'S':
- fStress = true;
- break;
-
- default:
- argc = 0;
- Printf("WARNING: Option at and after '%s' not understood!\n", str);
- break;
- }
-
- }
- if (fStress)
- {
- Printf("\nINFO: Running %u iterations of %u operations, resolution = %u\n",
- fIterations, fNumOperations, fResolution);
- Printf("INFO: Random Schedule from %u to %u milliseconds\n",
- fMinSchedule, fMaxSchedule);
- }
- }
-
- /*******************************************************************************
- ** PUBLIC RunStressTest
- ********************************************************************************/
-
- void TTestTimeScheduler::RunStressTest(Boolean)
- {
- size_t idx, jdx;
- TTimeOperation** ops;
- unsigned long sum[3];
- unsigned long sum2[3];
- unsigned long total[3];
-
- sum[0] = 0;
- sum[1] = 0;
- sum[2] = 0;
- sum2[0] = 0;
- sum2[1] = 0;
- sum2[2] = 0;
- total[0] = 0;
- total[1] = 0;
- total[2] = 0;
- ops = new TTimeOperation*[fNumOperations];
- if (ops == NULL)
- {
- Printf("ERROR: Out of Memory\n");
- return;
- }
- size_t count = 0;
- for (idx = 0; idx < fNumOperations; ++idx)
- {
- ops[idx] = new TTimeOperation(fTest, idx);
- if (ops[idx])
- {
- ops[idx]->fTest = 30;
- ops[idx]->fWatch = new TStopwatch;
- ops[idx]->fWhen = RandomNumber(fMinSchedule, fMaxSchedule);
- ops[idx]->SetTime(ops[idx]->fWhen);
- if (ops[idx]->fWatch == NULL)
- {
- delete ops[idx];
- ops[idx] = NULL;
- }
- else
- count += 1;
- }
- }
- if (count == 0)
- {
- Printf("ERROR: Out of Memory\n");
- return;
- }
- if (count != fNumOperations)
- {
- Printf("WARNING: Only enough memory to create %u operations\n", count);
- }
- for (jdx = 0; jdx < fNumOperations; ++jdx)
- {
- if (ops[jdx])
- fTest->Schedule(ops[jdx]);
- }
- Printf(" 0: ");
- for (idx = 0; idx < fIterations; ++idx)
- {
- Printf(".");
- if ((idx + 1) % 50 == 0)
- Printf("\n%8u: ", idx + 1);
- size_t cnt = 0;
- while (cnt < count)
- {
- for (jdx = 0; jdx < fNumOperations; ++jdx)
- {
- if (ops[jdx] && ops[jdx]->fFired)
- {
- int diff = ops[jdx]->fDifference;
- sum[0] += diff;
- sum2[0] += diff*diff;
- total[0] += 1;
- if (diff < 0)
- {
- sum[1] -= diff;
- sum2[1] += diff*diff;
- total[1] += 1;
- }
- else if (diff > 0)
- {
- sum[2] += diff;
- sum2[2] += diff*diff;
- total[2] += 1;
- }
-
- cnt += 1;
- ops[jdx]->fFired = false;
- ops[jdx]->fWhen = RandomNumber(fMinSchedule, fMaxSchedule);
- ops[jdx]->SetTime(ops[jdx]->fWhen);
- ops[jdx]->fWatch->Reset();
- fTest->Schedule(ops[jdx]);
- }
- }
- }
- }
- Printf("\nEnd of Test\n");
- Printf("Total fired = %u\n", total[0]);
- Printf("Average error = %u milliseconds\n", sum[0]/total[0]);
- Printf("Variance = %u\n\n",
- (total[0]*sum2[0] - sum[0]*sum[0])/(total[0]*(total[0] - 1)));
- if (total[1] > 1)
- {
- Printf("Total early fires = %u\n", total[1]);
- Printf("Average error = %u milliseconds\n", sum[1]/total[1]);
- Printf("Variance = %u\n\n",
- (total[1]*sum2[1] - sum[1]*sum[1])/(total[1]*(total[1] - 1)));
- }
- if (total[2] > 1)
- {
- Printf("Total late fires = %u\n", total[2]);
- Printf("Average error = %u milliseconds\n", sum[2]/total[2]);
- Printf("Variance = %u\n\n",
- (total[2]*sum2[2] - sum[2]*sum[2])/(total[2]*(total[2] - 1)));
- }
- jdx = 0;
- while (jdx < fNumOperations)
- {
- if (ops[jdx] == NULL || ops[jdx]->fFired)
- {
- if (ops[jdx])
- {
- ops[jdx]->fTest = 9;
- delete ops[jdx];
- }
- jdx += 1;
- }
- }
- delete ops;
- }
-
- /**********************************************************************
- ** PUBLIC RunTestIteration
- ***********************************************************************/
-
- void TTestTimeScheduler :: RunTestIteration(BooleanParm verbose, BooleanParm)
- {
- if (fStress)
- {
- RunStressTest(verbose);
- return;
- }
-
- unsigned short idx, jdx;
- Boolean flags[kNumOps];
- TTimeOperation* ops[kNumOps];
- TStopwatch* start;
- unsigned long timers[kNumOps];
- unsigned long stamps[kNumOps];
- unsigned short num = kNumOps;
-
- if (verbose)
- Printf("INFO: Creating %u TTimeOperation objects\n", num);
-
- for (idx = 0; idx < num; ++idx)
- {
- ops[idx] = new TTimeOperation(fTest, idx);
- ops[idx]->fTest = 0;
- }
- start = new TStopwatch;
-
- /* -----------------------------------------------------------------
- First, try 1 and 10 milliseconds resolution with a straightforward
- scheduling
- ----------------------------------------------------------------- */
-
- for (idx = 0; idx < 2; ++idx)
- {
- if (verbose)
- {
- Printf("INFO: Testing scheduling ");
- if (idx == 0)
- Printf("forward ");
- else
- Printf("backwards ");
- Printf(" ");
- }
- for (jdx = 0; jdx < num; ++jdx)
- {
- timers[jdx] = jdx*1000 + 1000;
- ops[jdx]->fFired = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
-
- start->Reset();
- if (idx != 0)
- {
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[num - 1 - jdx]);
- }
- else
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- Boolean ready = false;
- while (!ready)
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- }
- }
- Printf("\n");
- for (jdx = 0; jdx < num; ++jdx)
- {
- if (stamps[jdx] < timers[jdx] - kCloseness || stamps[jdx] > timers[jdx] + kCloseness)
- Printf(" WARNING: Timer%u (%u) fired at T=%u milliseconds\n", jdx + 1, timers[jdx],
- stamps[jdx]);
- }
- }
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
- for (idx = 0; idx < num - 1; ++idx)
- {
- if (verbose)
- Printf("INFO: Testing Duplicate on #%u ", idx + 1);
- for (jdx = 0; jdx < num - 1; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- timers[num - 1] = timers[idx];
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- Boolean ready = false;
- while (!ready && start->ElapsedMilliseconds() < timers[num - 2] + 500)
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- short dots = 0;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- ++dots;
- }
- while (dots--)
- Printf(".");
- }
- Printf("\n");
- for (jdx = 0; jdx < num; ++jdx)
- {
- if (stamps[jdx] < timers[jdx] - kCloseness || stamps[jdx] > timers[jdx] + kCloseness)
- Printf(" WARNING: Timer%u (%u) fired at T=%u milliseconds\n", jdx + 1, timers[jdx],
- stamps[jdx]);
- }
- }
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
-
- for (idx = 0; idx < num; ++idx)
- {
- if (verbose)
- Printf("INFO: Testing Removal by pointer of #%u ", idx + 1);
-
- for (jdx = 0; jdx < num; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- if (!fTest->Remove(ops[idx]))
- Printf("\n ERROR: Removal of Timer #%u failed\n", idx + 1);
-
- Boolean ready = false;
- while (!ready && (idx != num - 1 || start->ElapsedMilliseconds() < timers[num - 1] + 500))
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (jdx != idx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- if (jdx == idx)
- Printf("\n ERROR: Bummer - Timer #%u Fired\n", jdx + 1);
- }
- }
- Printf("\n");
- for (jdx = 0; jdx < num; ++jdx)
- {
- if (ops[jdx]->fFired == 0)
- continue;
- if (stamps[jdx] < timers[jdx] - kCloseness || stamps[jdx] > timers[jdx] + kCloseness)
- Printf(" WARNING: Timer%u (%u) fired at T=%u milliseconds\n", jdx + 1, timers[jdx],
- stamps[jdx]);
- }
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
- }
-
- for (idx = 0; idx < num; ++idx)
- {
- TTimeMatcher match(idx);
-
- if (verbose)
- Printf("INFO: Testing Removal by matchObject of #%u ", idx + 1);
-
- for (jdx = 0; jdx < num; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- TOperation* op = fTest->Remove(match);
- if (!op)
- Printf("\n ERROR: Removal of Timer #%u failed\n", idx + 1);
- if (op != ops[idx])
- Printf("\n ERROR: Removal of Timer #%u did not return the correct operation\n", idx + 1);
-
- Boolean ready = false;
- while (!ready && (idx != num - 1 || start->ElapsedMilliseconds() < timers[num - 1] + 500))
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (jdx != idx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- if (jdx == idx)
- Printf("\n ERROR: Bummer - Timer #%u Fired\n", jdx + 1);
- }
- }
- Printf("\n");
- for (jdx = 0; jdx < num; ++jdx)
- {
- if (ops[jdx]->fFired == 0)
- continue;
- if (stamps[jdx] < timers[jdx] - kCloseness || stamps[jdx] > timers[jdx] + kCloseness)
- Printf(" WARNING: Timer%u (%u) fired at T=%u milliseconds\n", jdx + 1, timers[jdx],
- stamps[jdx]);
- }
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
- }
-
-
- for (idx = 0; idx < num; ++idx)
- {
- if (verbose)
- Printf("INFO: Testing Removal/Acknowledge while in Process of #%u ", idx + 1);
-
- for (jdx = 0; jdx < num; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->fTest = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
- ops[idx]->fTest = 1;
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- Boolean ready = false;
- while (!ready)
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- }
- }
- Printf("\n");
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
- }
-
- for (idx = 0; idx < num; ++idx)
- {
- if (verbose)
- Printf("INFO: Testing Removal/Rerun while in Process of #%u ", idx + 1);
-
- for (jdx = 0; jdx < num; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->fTest = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
- ops[idx]->fTest = 2;
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- Boolean ready = false;
- while (!ready)
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- }
- }
- Printf("\n");
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
- }
-
-
- if (verbose)
- Printf("INFO: Testing single Reschedule\n");
- timers[0] = 1000;
- ops[0]->fFired = 0;
- ops[0]->fTest = 0;
- ops[0]->SetTime(timers[0]);
- flags[0] = 0;
- start->Reset();
- fTest->Schedule(ops[0]);
- if (fTest->IsEmpty())
- Printf("ERROR: TTimeScheduler thinks it is empty when it is not!\n");
- if (!fTest->Remove(ops[0]))
- Printf("ERROR: could not remove the TOperation!\n");
- else
- {
- ops[0]->SetTime(3000);
- timers[0] = 3000;
- fTest->Schedule(ops[0]);
- }
- while (ops[0]->fFired == 0)
- ;
- stamps[0] = start->ElapsedMilliseconds();
- if (stamps[0] < 3000 - kCloseness || stamps[0] > 3000 + kCloseness)
- {
- Printf("WARNING: Timer fired at %u\n", stamps[0]);
- }
-
- for (idx = 0; idx < num; ++idx)
- {
- if (verbose)
- Printf("INFO: Testing Reschedule while in Process of #%u ", idx + 1);
-
- for (jdx = 0; jdx < num; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->fTest = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
- ops[idx]->fTest = 4;
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- Boolean ready = false;
- while (!ready)
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- }
- }
- while (ops[idx]->fTest != 20 && start->ElapsedMilliseconds() < num*1000)
- ;
- stamps[idx] = start->ElapsedMilliseconds();
- Printf("\n");
- if (ops[idx]->fTest != 20)
- Printf(" ERROR: Timer#%u did not fire a second time\n", idx + 1);
- else
- if (stamps[idx] < 3500 - kCloseness || stamps[idx] > 3500 + kCloseness)
- {
- Printf(" WARNING: Timer#%u (%u) fired at %u\n",
- idx + 1, 3500, stamps[idx]);
- }
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
- }
-
- for (idx = 0; idx < num; ++idx)
- {
- if (verbose)
- Printf("INFO: Testing Remove/Reschedule while in Process of #%u ", idx + 1);
-
- for (jdx = 0; jdx < num; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->fTest = 0;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
- ops[idx]->fTest = 6;
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- Boolean ready = false;
- while (!ready)
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- }
- }
- Printf("\n");
- if (!fTest->IsEmpty())
- {
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
- while (ops[idx]->fTest != 21 && start->ElapsedMilliseconds() < num*1000)
- ;
- if (ops[idx]->fTest == 21)
- Printf(" ERROR: Timer#%u fired a second time\n", idx + 1);
- }
- }
-
- if (verbose)
- Printf("INFO: Testing Removal/Delete ", idx + 1);
-
- for (jdx = 0; jdx < num; ++jdx)
- timers[jdx] = jdx*500 + 500;
-
- for (jdx = 0; jdx < num; ++jdx)
- {
- ops[jdx]->fFired = 0;
- ops[jdx]->fTest = 8;
- ops[jdx]->SetTime(timers[jdx]);
- flags[jdx] = 0;
- }
-
- start->Reset();
- for (jdx = 0; jdx < num; ++jdx)
- fTest->Schedule(ops[jdx]);
-
- if (fTest->IsEmpty())
- Printf("\n ERROR: TTimeScheduler thinks it is empty when it is not!\n");
-
- Boolean ready = false;
- while (!ready)
- {
- ready = true;
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- {
- ready = false;
- break;
- }
-
- for (jdx = 0; jdx < num; ++jdx)
- if (!flags[jdx])
- if (ops[jdx]->fFired)
- {
- flags[jdx] = true;
- stamps[jdx] = start->ElapsedMilliseconds();
- Printf(".");
- }
- }
- Printf("\n");
- for (jdx = 0; jdx < num; ++jdx)
- {
- if (ops[jdx]->fTest != 10)
- Printf("ERROR: Timer%u (%u) did not delete itself\n", jdx + 1, timers[jdx]);
- if (ops[jdx]->fFired == 0)
- continue;
- }
- if (!fTest->IsEmpty())
- Printf(" ERROR: TTimeScheduler does not think it is empty!\n");
-
- delete start;
- }
-
- /**********************************************************************
- ** PUBLIC EndTest
- ***********************************************************************/
-
- void TTestTimeScheduler :: EndTest(BooleanParm, BooleanParm)
- {
- delete fTest;
- fTest = NULL;
- }
-